﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Web;
using System.Web.UI;
using System.Web.UI.HtmlControls;

namespace WebeTerm.Common
{
    public class ViewManager<T> where T : System.Web.UI.Control
    {
        private Page m_pageHolder;
        private T control;
        public T Control
        {
            get { return control; }
            set { control = value; }
        }

        public T LoadViewControl(string path)
        {
            this.m_pageHolder = new Page();
            control = (T)this.m_pageHolder.LoadControl(path);
            return control;
        }

        public string RenderView()
        {
            StringWriter output = new StringWriter();
            this.m_pageHolder.Controls.Add(control);

            HttpContext.Current.Server.Execute(m_pageHolder, output, false);

            return output.ToString();
        }
    }
}
